const { Controller } = require("egg");

const { getReqParams, getResBody, getResList, getPageParams, getReqToken } = require("../../utils");
const validRules = require("../../utils/valid/rules");

const tableName = "topic";
const tables = [
  // {
  //   topic: [
  //     "*",
  //     "(SELECT COUNT(*) FROM user_relations WHERE focused_id = user.id) AS fans_num",
  //     "(SELECT COUNT(*) FROM user_relations WHERE focus_id = user.id) AS focus_num",
  //     "(SELECT COUNT(*) FROM system_notice WHERE accept_id = user.id) AS notice_num",
  //     "(SELECT COUNT(*) FROM visitor WHERE visited_id = user.id) AS visitor_num",
  //   ],
  // },
  // {
  //   "note|LEFT JOIN note ON user.id=note.create_id": [
  //     "COUNT(DISTINCT note.id) AS note_num",
  //     "SUM(DISTINCT note.praise_num) AS praise_num",
  //     "SUM(DISTINCT note.belittle_num) AS belittle_num",
  //     "SUM(DISTINCT note.collect_num) AS collect_num",
  //     "SUM(DISTINCT note.share_num) AS share_num",
  //     "SUM(DISTINCT note.report_num) AS report_num",
  //     "AVG(DISTINCT note.score) AS score",
  //   ],
  // },
];
const filter = {
  // 其他条件，例：笔记未删除、用户未注销等
  // "sn.type|<=": 15,
};
module.exports = class UserController extends Controller {
  // 查详情
  async detail() {
    const { ctx, service } = this;
    const rules = { id: validRules.id };
    const params = getReqParams(ctx, rules);
    if (!params) return;
    const { tableName, addParams } = ctx;
    const data = await service.common.detail(tables, { where: { ...params, ...filter }, group: ["user.id"] }); // "sn.accept_id"
    ctx.body = getResBody({ data });
  }
};
